22

How should I configure PHPStorm so that I can trace my code using XDebug when running console commands?

I know I have the debug configuration correct, because I can debug web requests and trace the code. I can also trace regular php command line scripts as long as I set an environment variable like this:

export XDEBUG_CONFIG="idekey=my-xdebug"

However, I am unable to trace/debug Symfony2 console commands (those run with app/console bundle:console_command). PhpStorm sees the connection, however, it can't seem to locate the code that is being run. I know my file mapping is correct because web requests work flawlessly.

Is this possible?

1
  • 1
    Enable logging from xdebug side and see what file it is running ... and then see if your mappings are correct. Commented Sep 28, 2014 at 10:10

3 Answers 3

27

You should provide SERVER_NAME and SERVER_PORT. also you should enable xdebug.remote_autostart. Try this:

SERVER_PORT=<Your port> SERVER_NAME='<Your server> php \
    -dxdebug.remote_autostart=On app/console test
Sign up to request clarification or add additional context in comments.

4 Comments

php -dxdebug.remote_autostart=On app/console my:cmd works. Thanks
Thanks it works perfectly , you should check this as the working answer ;)
@tom10271 you are the real MVP
FYI, the modern day version if this is php -dxdebug.start_with_request=yes bin/console my:cmd
7

Make sure you have enabled xdebug inside php.ini CLI version not only apache/cgi php.ini.

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM

1 Comment

you should also add xdebug.remote_autostart = 1 and be sure that your mappings are correct in the debug configuration of the IDE
1

I'm suggesting to try following BASH helper command: https://github.com/torinaki/phpdebug-cli

phpdebug mostly autodetects all required configurations and you will not require to provide environment variables.

Just run:

phpdebug app/console bundle:console_command

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.